package com.atguigu.tingshu.comment.api;

import com.atguigu.tingshu.comment.service.CommentService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.vo.comment.CommentVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("api/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    // Request URL: http://localhost:8500/api/comment/findCommentPage/1593/51951/1/30
    @GetMapping("findCommentPage/{albumId}/{trackId}/{pn}/{pz}")
    @Operation(summary = "分页查询专辑下的声音评论")
    public Result findCommentPage(@PathVariable Long albumId,
                                  @PathVariable Long trackId,
                                  @PathVariable Long pn,
                                  @PathVariable Long pz) {
        IPage<CommentVo> page = new Page<>(pn, pz);
        page = commentService.findCommentPage(page, albumId, trackId);
        return Result.ok(page);
    }

    // Request URL: http://localhost:8500/api/comment/save
    @Operation(summary = "保存评论")
    @PostMapping("save")
    public Result save(@RequestBody CommentVo commentVo) {
        commentService.save(commentVo);
        return Result.ok();
    }
}
